<?php
header("Content-Type:text/html;charset=utf-8");
session_start();
include 'includes/init.php';
//$unname=isset($_REQUEST['username'])?$_REQUEST['username']:$_SESSION['uesrname'];
//$phone=isset($_REQUEST['phone'])?$_REQUEST['phone']:'';
//密钥
$key_base = "eimsymyctwomingpu";
$iv_base = "mingpuciguangdia";
$key = md5($key_base);
$iv = $iv_base;
//解密参数
if (isset($_REQUEST['code1'])){
    $unname = $_REQUEST['code1'];
} else {
    $unname = $_SESSION['uesrname'];
}
if (isset($_REQUEST['code2'])){
    $code2 = $_REQUEST['code2'];
    $cryptText = base64_decode($code2);
    $phone = mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$key,$cryptText,MCRYPT_MODE_CBC,$iv);
} else {
    $phone = $_SESSION['phone'];
}

if (empty($unname)) {
	header('Location:login.php');
	
	die();
}
error_log('username: '.$unname);
error_log('phone: '.$phone);
//查询用户信息
$sql_login="select * from t_member where names = '$unname' or phone = '$phone'";
error_log('login sql: '.$sql_login);
$resArr1=$db_Obj->getone($sql_login);
if (!empty($resArr1)) {
 
    $id = intval($resArr1['id']);
    $_SESSION['uesrname'] = $resArr1['names'];
    $_SESSION['id'] = $id;
    $_SESSION['phone'] = $resArr1['phone'];
  
  
}
echo '欢迎您：',$unname,"<a href='login.php?act=loginout' style='margin-left:10px;color:blue' target='_parent'>退出登录</a>";
echo "<a href = 'reg_pwd.php?id=".$id."' style='margin-left:10px;color:red'>修改密码</a>";
	$sql = "select rule_id from t_member where id = ".$id." ";
	$user_type = $db_Obj->getone($sql);
	
	// 普通用戶(供应商) rule_id = 1 
	if($user_type['rule_id'] == 1){
	    error_log('step 1');
		$sql = "select distinct project from t_product where sid like '%".$id."%' ";
		$resArr = $db_Obj ->getall($sql);           //返回所有项目的列表
		$time = time();
		// 检测该项目数据是否过期
		foreach ($resArr as $key => $value) {
			$sql="select * from t_product  where  (mifeng = 0 and lasttime > ".$time." or mifeng = 1 and lasttime > ".$time." )  and project='".$value['project']."' ";
			$infoall=$db_Obj->getall($sql);         //0为非密封，1为密封
			if(empty($infoall)){
				unset($resArr[$key]);           //去除过期项目
			}
		}
	}
	//  管理员 (需求商) rule_id = 2
	if($user_type['rule_id'] == 2){
        error_log('step 2');
		$info = 1;
        $_SESSION['rule_id'] = 2;
	}
	// 领导 rule_id = 3
	if($user_type['rule_id'] == 3){
        error_log('step 3');
		// 审批等级证
//		$sql = "select * from t_member where ( names = '".$unname."' and names = '经理' ) or ( names = '".$unname."' and names = '总监' )   ";
		$sql = "select * from t_member where rule_id = 3  ";
		$usr_data = $db_Obj->getone($sql);
	}
	// 归档人 rule_id = 4
	if($user_type['rule_id'] == 4){
        error_log('step 4');
		$sql = "select * from t_member where names = '".$unname."' and names ='归档人' ";
		$gui_usrdata = $db_Obj->getone($sql);
	}

	//超级管理员 rule_id = 5
    if($user_type['rule_id'] == 5){
    error_log('step 5');
    $admin_data = true;
    $_SESSION['rule_id'] = 5;
}


include 'index.html';
